const { DataTypes } = require('sequelize');
const sequelize = require('../config/db');

const User = sequelize.define('User', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        comment: '用户ID'
    },
    username: {
        type: DataTypes.STRING(20),
        allowNull: false,
        unique: true,
        comment: '用户账号名'
    },
    password: {
        type: DataTypes.STRING(20),
        allowNull: false,
        comment: '密码'
    },
    email: {
        type: DataTypes.STRING(40),
        allowNull: true,
        unique: true,
        comment: '邮件'
    },
    phone_number: {
        type: DataTypes.STRING(20),
        allowNull: true,
        comment: '电话号码'
    },
    createdAt: {
        type: DataTypes.DATE,
        defaultValue: DataTypes.NOW,
        field: 'created_at'
    },
    updatedAt: {
        type: DataTypes.DATE,
        defaultValue: DataTypes.NOW,
        field: 'updated_at'
    },
    lease_count: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: '租赁数量'
    },
    address: {
        type: DataTypes.STRING(255),
        allowNull: true,
        comment: '收获地址'
    },
    birthday: {
        type: DataTypes.DATE,
        allowNull: true,
        comment: '用户生日'
    },
    real_name: {
        type: DataTypes.STRING(20),
        allowNull: true,
        comment: '真实姓名'
    },
    sex: {
        type: DataTypes.TINYINT,
        allowNull: true,
        comment: '性别'
    },
}, {
    tableName: 'users',
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at',
});

module.exports = User;